<template>
  <el-dialog v-model="dialogFormVisible" title="关联证照">
    <el-form
      :model="formData"
      ref="queryRef"
      :inline="true"
      label-width="80px"
      class="searchForm"
    >
      <el-form-item label="选择关联证照">
        <el-select v-model="formData.fileId" placeholder="" style="width: 100%">
          <el-option
            v-for="ele in list"
            :key="ele.id"
            :value="ele.id"
            :label="ele.reportsName"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="onSubmit"> 确 认 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive, defineProps, ref, defineEmits, defineExpose } from "vue";
import { apis as APIS } from "@/api/aqsc/xkzgl.js";
import { relation } from "@/api/aqsc/tzss/relation.js";
const props = defineProps({
  title: {
    type: String,
  },
  type: {
    type: String,
  },
  width: {
    type: String,
  },
  done: {
    type: Function,
  },
});
const list = ref([]);
const dialogFormVisible = ref(false);
const open = (data) => {
  dialogFormVisible.value = true;
  formData.value.metadataId = data;
};
const close = () => {
  dialogFormVisible.value = false;
};
const formData = ref({
  confViewName: "",
  metadataId: "",
  fileId: "",
});
const emits = defineEmits(["onSubmit"]);

const onSubmit = async () => {
  try {
    relation(formData.value).then((res) => {
      close();
      props.done();
    });
    return formData;
  } catch (error) {
    return false;
  }
};
onMounted(() => {
  APIS.query({
    type: 2,
    pageNum: 1,
    pageSize: 9999999999999,
  }).then((res) => {
    list.value = res.rows;
  });
  formData.value.confViewName = props.type;
});
defineExpose({
  onSubmit,
  open,
  close,
});
</script>

<style lang="scss" scoped></style>
